# (C) Copyright 2016-2023 Intel Corporation.
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
"""Build libgurt"""

SRC = ['debug.c', 'dlog.c', 'hash.c', 'misc.c', 'heap.c', 'errno.c',
       'fault_inject.c', 'slab.c', 'telemetry.c', 'hlc.c', 'hlct.c', 'signals.c']


def scons():
    """Scons function"""

    Import('env', 'prereqs', 'CART_VERSION')

    env.d_add_build_rpath()
    env.AppendUnique(LIBPATH=[Dir('.')])
    env.AppendUnique(CPPPATH=[Dir('.').srcnode()])

    denv = env.Clone()

    denv.AppendUnique(LIBS=['pthread', 'yaml', 'm', 'dl'])
    denv.require('uuid')

    gurt_targets = denv.SharedObject(SRC)
    gurt_lib = denv.d_library('gurt', gurt_targets, SHLIBVERSION=CART_VERSION)
    denv.InstallVersionedLib('$PREFIX/lib64/', gurt_lib, SHLIBVERSION=CART_VERSION)

    Export('gurt_targets')

    SConscript('examples/SConscript')

    if prereqs.test_requested():
        SConscript('tests/SConscript')


if __name__ == "SCons.Script":
    scons()
